package com.linzelin;

import redis.clients.jedis.Jedis;
import java.util.Set;

public class TestPing {
    public static void main(String[] args) {
        /*连接到Redis,这里只需要new Jedis对象即可*/
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        /*测试指令,这些指令其实就是对象里面对应的方法*/

        System.out.println("flushdb : "+jedis.flushDB());
        System.out.println("exists : "+jedis.exists("username"));
        System.out.println("new<username,lin> : "+jedis.set("username","lin"));
        System.out.println("new<password,123456> : "+jedis.set("password","123456"));
        System.out.println("allkey : ");
        Set<String> keys = jedis.keys("*");
        System.out.println(keys);

        System.out.println("delete : "+jedis.del("password"));
        System.out.println("exits -- password : "+jedis.type("password"));
        System.out.println("type--username : "+jedis.type("username"));
        System.out.println("get random key : "+jedis.randomKey());
        System.out.println("rename--username : "+jedis.rename("username","name"));
        System.out.println("get name : "+jedis.get("name"));
        System.out.println(jedis.select(0));
        System.out.println("delete all key : "+jedis.flushDB());
        System.out.println("get keys :"+jedis.dbSize());
        System.out.println("delete all keys from all datasource : "+jedis.flushAll());

        /*flushdb : OK
          exists : false
          new<username,lin> : OK
          new<password,123456> : OK
          allkey :
          [password, username]
          delete : 1
          exits -- password : none
          type--username : string
          get random key : username
          rename--username : OK
          get name : lin
          OK
          delete all key : OK
          get keys :0
          delete all keys from all datasource : OK*/
    }
}
